# # 形参和实参_文档字符串_函数的注释 关键字:def
# # def print_max(a, b):
# #  if a > b:
# #   print(a, "是较大值")
# #   return a
# #  else:
# #   print(b, "是较大值")
# #   return b
# #
# #
# # print_max(10, 20)
# # help(print_max)
#
#
# # #函数也是对象_内存分析;在定义过def函数后实际上创建了相应的函数对象
# # def print_star(n):
# #     print("*"*n)
# #
# #
# # c=print_star
# # c(3)
# #
# # print(print_star)  #不用加上() 因为他是执行符号不加上表示不执行
# # # print(id(print_star))
# # print(type(print_star))
#
# # 变量的作用域_全局变量_局部变量_栈帧内存分析讲解
# # a=100
# # def f1():
# #   b=3
# #   global a #可以修改全局变量的值
# #   a=7
# #   print(a+b)
# #
# #
# # f1()
# # print(a)
#

#  a=100
#  def f1(a,b,c):
#    print(a,b,c)
#   print(locals())   #打印局部变量
#    print("#"*20)
#    print(globals())  #打印全局变量
#
#  f1(2,3,4)
#
#
# # 局部变量和全局变量_效率测试
# import time
# a = 1000
# def test01():
#     start = time.time()
#     global a
#     for i in range(100000000):
#         a += 1
#     end = time.time()
#     print("耗时{0}".format((end-start)))
#
# def test02():
#     start=time.time()
#     c=1000
#     for i in range(100000000):
#      c+=1
#     end=time.time()
#     print("耗时{0}".format((end-start)))
#
# test01()
# test02()

#
#
# #参数的传递_传递可变对象_内存分析
# a=100
# def f1(n):
#    print("n:",id(n))    #传进来的是a的地址
#    n=n+200
#    print("n:",n)
#
# f1(a)                          #调用f1()  函数将a赋值给了n
# print("a:",id(a))


#浅拷贝和深拷贝_
import copy

# def testCopy():
#     a=[10,20,[5,6]]
#     b=copy.copy(a)
#
#     print("a",a)
#     print("b",b)
#     b.append(30)
#     b[2].append(7)
#     print("浅拷贝............")
#     print("a",a)
#     print("b",b)


# #深拷贝
# def testDeepCopy():
#     a = [10,20,[5,6]]
#     b=copy.deepcopy(a)
#     print("a",a)
#     print("b",b)
#     b.append(30)
#     b[2].append(7)
#     print("深拷贝............")
#     print("a",a)
#     print("b",b)
# # testCopy()
# testDeepCopy()





#参数的传递_不可变对象含可变子对象
# a=(10,20,[5,6])
# print("a:",id(a))
#
# def test01(m):
#     print("m:",id(m))
#     m[2][0]=888
#     print("m",m)
#     print("m",id(m))
#
# test01(a)
# print(a)  #改变了子对象,源对象也随之变化


#参数的类型_位置参数_默认值参数_命名参数

# def f1(a,b,c):
#     print(a,b,c)
#
# f1(1,2,3)

# def f2(a,b,c=10,d=20):
#     print(a,b,c,d)
# f2(8,9,19,90)

# def f3(a,b,c,d):
#     print(a,b,c,d)
#
# f3(c=20,b=10,a=199,d=77)  #通过名字传递参数


#参数的类型_可变参数_强制命名参数
# def f1(a,b,*c):  #*c数字以元组的形式进行打印 *pram
#     print(a,b,c)
# f1(8,9,10,98)

# def f2(a,b,**c):
#     print(a,b,c)
# f2(10,20,name="gapqi",age=18)  #10 20 {'name': 'gapqi', 'age': 18}

#lambda表达式和匿名函数
# f=lambda a,b,c:a+b+c
# print(f)
# print(id(f))
# print(type(f))
# print(f(10,20,30))
#
# g=[lambda a:a*2,lambda b:b*3,lambda c:c*4]
# print(g[0](8),g[1](4),g[2](2))


#
# #eval()函数的用法和注入安全隐患问题
# s="print('abcde')"
# eval(s)
#
# dict1=dict(a=100,b=200)
# d=eval("a+b",dict1)
# print(d)



#递归函数_函数调用内存分析_栈帧的创建
# def f1(n):
#     print("start:"+str(n))
#     if n==1:
#         print("over!")
#     else:
#         f1(3-1)
#         print("end:"+str(3))
#
# f1(3)

#递归函数_阶乘计算案例

# def factorial(n):
#     if n==1:
#         return 1
#     else:
#         return n*factorial(n-1)
#
# factorial(5)
# print(factorial(5))
#


#嵌套函数_内部函数_数据隐藏3
# def outer():
#     print("out running!")
#
#     def inner():
#         print("inner running!")
#     inner()
#
# outer()


# def printChineseName(name,familyName):
#     print("{0} {1}".format(familyName,name))
#
# def printEnglishName(name,familyName):
#     print("{0} {1}".format(familyName,name))
#
# def printName(isChinese,name,familyName):
#     def inner_print(a,b):
#         print("{0},{1}".format(a,b))
#
#     if isChinese:
#         inner_print(familyName,name)
#     else:
#         inner_print(name,familyName)
#
# printName(True,"冠宇","陈")
# printName(False,"gunayu","chen")


